/*
 * @Author: humengchuan 531537052@qq.com
 * @Date: 2024-05-21 14:14:48
 * @LastEditors: humengchuan 531537052@qq.com
 * @LastEditTime: 2024-05-21 17:26:56
 * @FilePath: \project\record-work-time\src\utils\tools.js
 * @Description: 
 */
export function getCurrentDayOfWeek() {  
    const daysOfWeek = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];  
    const currentDate = new Date();  
    const dayOfWeekIndex = currentDate.getDay();  
      
    return daysOfWeek[dayOfWeekIndex];  
}  

export function removeHtmlTags(text) {
  return text.replace(/<[^>]*>/g, '');
}


/**
 * 获取当前时间，根据sort参数返回不同的时间格式
 * @param {string} sort 指定返回的时间格式，可选值为 'year', 'month', 'day'，若未提供则返回 null
 * @returns {number|string|null} 根据sort参数返回对应的年份（数字类型）、月份（两位数字符串）或日期（两位数字符串），若sort参数无效则返回null
 */
export function getCurrentTime(sort) {  

  if(!sort) return null

  const currentDate = new Date();  
  if(sort === 'year') {
    return currentDate.getFullYear()
  }
  if(sort === 'month') {
    let month = currentDate.getMonth() + 1
    return month > 9 ? month : '0' + month
  }
  if(sort === 'day') {
    let day = currentDate.getDate()
    return day > 9 ? day : '0' + day
  }
}